package hku.cs.lunuo.views;

import hku.cs.lunuo.LunuoPlugin;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;

import org.eclipse.core.runtime.FileLocator;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.swt.graphics.Image;

public class RankLableProvider extends LabelProvider implements ITableLabelProvider{
	Image images;
	
	public RankLableProvider() {
		images= createImage("icons/sample.gif"); //$NON-NLS-1$
	}
	
	private static Image createImage(String path) {
		ImageDescriptor descriptor= null;
		try {
			URL url = null;
			url = FileLocator.getBundleFile(LunuoPlugin.getDefault().getBundle()).toURI().toURL();
			descriptor= ImageDescriptor.createFromURL(new URL(url, path));
		} catch (MalformedURLException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		} catch (IOException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		return descriptor.createImage();  
	}
	
	@Override
	public Image getColumnImage(Object element, int columnIndex) {
		if(columnIndex==0)
			return images;
		else return null;
	}

	@Override
	public String getColumnText(Object element, int columnIndex) {
		Rank r = (Rank)element;
		
		String ret="";
		switch (columnIndex){
		case 0:
			break;
		case 1:
			ret = Integer.toString(r.getIndex());
			break;
		case 2:
			ret = Integer.toString(r.getRank());
			break;
		case 3:
			ret = Float.toString(r.getSuspicious());
			break;
		case 4:
			ret = Integer.toString(r.getLine());
			break;
		case 5:
			ret = r.getKlass();
			break;
		default:
			ret = "";
		}
		
		return ret;
	}
	
	public void dispose() {
		images.dispose();
	}

}
